package com.sise.aio和bio和nio.nio.nio的buffer学习;

import java.nio.ByteBuffer;

/**
 * @author idea
 * @data 2019/1/20
 */
public class Test {

    public static void main(String[] args) {
        String content="idea";
        ByteBuffer by=ByteBuffer.allocate(1024);
        System.out.println("第一次分配空间");
        System.out.println(by.position());
        System.out.println(by.limit());
        System.out.println(by.capacity());

        System.out.println("读取数据之后");
        by.put(content.getBytes());
        System.out.println(by.position());
        System.out.println(by.limit());
        System.out.println(by.capacity());

        by.flip();
        System.out.println("切换为了读模式");
        System.out.println(by.position());
        System.out.println(by.limit());
        System.out.println(by.capacity());
//        ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
//        System.out.println("第一次分配空间");
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());
//
//        byteBuffer.put(content.getBytes());
//        System.out.println("输入数据之后");
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());
//
        by.flip();
        System.out.println("切换读写状态");
        System.out.println(by.position());
        System.out.println(by.limit());
        System.out.println(by.capacity());
//
//
//        //此时数据并没有被清空 limit又重新变为了capacity
        by.clear();
        System.out.println("数据处于被遗忘状态");
        System.out.println(by.position());
        System.out.println(by.limit());
        System.out.println(by.capacity());
//
//
//        System.out.println((char)byteBuffer.get());
//
//        System.out.println("判断数据缓冲区是否有剩余");
//        if(byteBuffer.hasRemaining()){
//            System.out.println(byteBuffer.remaining());
//        }
    }
}
